package com.neu.gulimall.order.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

//@EnableConfigurationProperties(ThreadPoolConfigProperties.class) 如果 ThreadPoolConfigProperties没有放入到容器中,就可以通过这种方式使用自定义配置
@Configuration
public class MyThreadPoolConfig {

   @Bean
   public ThreadPoolExecutor threadPoolExecutor(ThreadPoolConfigProperties pool){
       ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
               pool.getCoreSize(),
               pool.getMaxSize(),
               pool.getKeepAliveTime(),
               TimeUnit.SECONDS,
               new LinkedBlockingQueue<>(100000),
               Executors.defaultThreadFactory(),
               new ThreadPoolExecutor.AbortPolicy());

       return threadPoolExecutor;
   }


}
